﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="PhotoLabs.ItemDetailPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:PhotoLabs"
    xmlns:data="using:PhotoLabs.Data"
    xmlns:common="using:PhotoLabs.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>

        <!-- Collection of items displayed by this page -->
        <CollectionViewSource
            x:Name="itemsViewSource"
            Source="{Binding Items}"
            d:Source="{Binding AllGroups[0].Items, Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}"/>
    </Page.Resources>
    <Page.BottomAppBar>
        <AppBar x:Name="PageAppBar" Padding="10,0,10,0">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50*"/>
                    <ColumnDefinition Width="50*"/>
                </Grid.ColumnDefinitions>
                <StackPanel x:Name="LeftCommands" Orientation="Horizontal" Grid.Column="0" HorizontalAlignment="Left">
                    <Button x:Name="PinRecipeButton"  HorizontalAlignment="Left" Style="{StaticResource PinAppBarButtonStyle}" Click="OnPinRecipeButtonClicked" />
                </StackPanel>
                <StackPanel x:Name="RightCommands" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.BottomAppBar>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid
        Style="{StaticResource LayoutRootStyle}"
        DataContext="{Binding Group}"
        d:DataContext="{Binding AllGroups[0], Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}">

        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--
            The remainder of the page is one large FlipView that displays details for
            one item at a time, allowing the user to flip through all items in the chosen
            group
        -->
        <FlipView
            x:Name="flipView"
            AutomationProperties.AutomationId="ItemsFlipView"
            AutomationProperties.Name="Item Details"
            TabIndex="1"
            Grid.RowSpan="2"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}">

            <FlipView.ItemContainerStyle>
                <Style TargetType="FlipViewItem">
                    <Setter Property="Margin" Value="0,137,0,0"/>
                </Style>
            </FlipView.ItemContainerStyle>

            <FlipView.ItemTemplate>
              

                    <!--
                        UserControl chosen as the templated item because it supports visual state management
                        Loaded/unloaded events explicitly subscribe to view state updates from the page
                    -->
                    <DataTemplate>
                        <UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates">
                            <ScrollViewer x:Name="scrollViewer" Style="{StaticResource VerticalScrollViewerStyle}" Grid.Row="1">

                                <Grid Margin="120,0,20,20">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="600" />
                                        <ColumnDefinition Width="40" />
                                        <ColumnDefinition Width="360" />
                                   
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>

                                    <StackPanel Orientation="Vertical" Grid.Column="0">
                                        <TextBlock FontSize="26.667" FontWeight="Light" Text="{Binding Title}" TextWrapping="Wrap"/>
                                        <Image x:Name="image" Width="600" Margin="0,20,0,10" Stretch="Uniform" Source="{Binding Image}"/>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock FontSize="26.667" FontWeight="Light" Text="Location:"/>
                                            <TextBlock FontSize="26.667" FontWeight="Light" Text="{Binding Location}" Margin="8,0,8,0"/>
                                        </StackPanel>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock FontSize="26.667" FontWeight="Light" Text="by"/>
                                        <TextBlock FontSize="26.667" FontWeight="Light" Text="{Binding Photographer}" Margin="8,0,8,0"/>
                                    </StackPanel>
                                </StackPanel>

                                    <StackPanel Orientation="Vertical" Grid.Column="2">
                                      
                                        <TextBlock FontSize="20" Margin="0,48,0,0" FontWeight="Light" LineHeight="32.5" Text="{Binding Quote}" TextWrapping="Wrap" />
                                    </StackPanel>

                                    <!--<StackPanel Orientation="Vertical" Grid.Column="4">
                                        <TextBlock FontSize="26.667" FontWeight="Light" Text="Directions" Margin="0,0,0,16"/>
                                        <ScrollViewer Style="{StaticResource VerticalScrollViewerStyle}">
                                            <Grid>
                                                <TextBlock FontSize="20" FontWeight="Light" Text="{Binding Directions}" TextWrapping="Wrap" />
                                            </Grid>
                                        </ScrollViewer>
                                    </StackPanel>-->
                                </Grid>

                          
                            </ScrollViewer>
                        </UserControl>
                

                </DataTemplate>
            </FlipView.ItemTemplate>
        </FlipView>
        <!-- FlipView used in portrait mode -->
        <FlipView
        x:Name="portraitFlipView"
        AutomationProperties.AutomationId="ItemsFlipView"
        AutomationProperties.Name="Item Details"
        Grid.Row="1"
        Margin="0,-3,20,0"
        ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
        Visibility="Collapsed">

                <FlipView.ItemTemplate>
                    <DataTemplate>
                        <UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates">
                            <ScrollViewer x:Name="scrollViewer" Style="{StaticResource VerticalScrollViewerStyle}" Grid.Row="1">

                                <!-- Vertical StackPanel for item-detail layout -->
                            <StackPanel>

                                <StackPanel Orientation="Vertical">
                                    <TextBlock FontSize="26.667" Margin="100,0,0,0" FontWeight="Light" Text="{Binding Title}" TextWrapping="Wrap"/>
                                    <Image x:Name="image" Width="600" Margin="0,20,0,10" Stretch="Uniform" Source="{Binding Image}"/>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock FontSize="26.667" Margin="100,0,0,0" FontWeight="Light" Text="Location:"/>
                                        <TextBlock FontSize="26.667"  FontWeight="Light" Text="{Binding Location}" Margin="8,0,8,0"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock FontSize="26.667" Margin="100,0,0,0" FontWeight="Light" Text="by"/>
                                        <TextBlock FontSize="26.667"  FontWeight="Light" Text="{Binding Photographer}" Margin="8,0,8,0"/>
                                    </StackPanel>
                                </StackPanel>

                                <StackPanel Orientation="Vertical" >

                                    <TextBlock FontSize="20" Margin="100,12,0,0" FontWeight="Light" LineHeight="32.5" Text="{Binding Quote}" TextWrapping="Wrap" />
                                </StackPanel>
                            </StackPanel>

  
                        </ScrollViewer>
                        </UserControl>
                    </DataTemplate>
                </FlipView.ItemTemplate>
        </FlipView>

        <FlipView
        x:Name="snappedFlipView"
        AutomationProperties.AutomationId="ItemsFlipView"
        AutomationProperties.Name="Item Details"
        Grid.Row="1"
        Margin="0,-3,20,0"
        ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
        Visibility="Collapsed">

            <FlipView.ItemTemplate>
                <DataTemplate>
                    <UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates">
                        <ScrollViewer x:Name="scrollViewer" Style="{StaticResource VerticalScrollViewerStyle}" Grid.Row="1">

                            <!-- Vertical StackPanel for item-detail layout -->
                            <StackPanel>

                                <StackPanel Orientation="Vertical">
                                    <TextBlock FontSize="26.667" Margin="10,0,0,0" FontWeight="Light" Text="{Binding Title}" TextWrapping="Wrap"/>
                                    <Image x:Name="image" Width="300" Margin="10,20,0,10" Stretch="Uniform" Source="{Binding Image}"/>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Style="{StaticResource BasicTextStyle}" Margin="10,0,0,0" FontWeight="Light" Text="Location:"/>
                                        <TextBlock Style="{StaticResource BasicTextStyle}" Text="{Binding Location}" Margin="8,0,8,0"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Style="{StaticResource BasicTextStyle}" Margin="10,0,0,0" FontWeight="Light" Text="by"/>
                                        <TextBlock Style="{StaticResource BasicTextStyle}" Text="{Binding Photographer}" Margin="8,0,8,0"/>
                                    </StackPanel>
                                </StackPanel>

                                <StackPanel Orientation="Vertical" >

                                    <TextBlock Style="{StaticResource BasicTextStyle}" Margin="10,12,0,0"  LineHeight="32.5" Text="{Binding Quote}" TextWrapping="Wrap" />
                                </StackPanel>
                            </StackPanel>


                        </ScrollViewer>
                    </UserControl>
                </DataTemplate>
            </FlipView.ItemTemplate>
        </FlipView>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Text="{Binding Title}" Style="{StaticResource PageHeaderTextStyle}" Grid.Column="1" IsHitTestVisible="false"/>
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The back button respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="flipView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="portraitFlipView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>

                    </Storyboard>
                    
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="flipView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="snappedFlipView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>

                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
